// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/testing/vector/vector_test_base.h>

namespace kumo::pollux::test {

    void assertEqualVectors(const VectorPtr &expected, const VectorPtr &actual) {
        ASSERT_EQ(expected->size(), actual->size());
        ASSERT_TRUE(expected->type()->equivalent(*actual->type()))
      << "Expected " << expected->type()->toString() << ", but got "
      << actual->type()->toString();
        for (auto i = 0; i < expected->size(); i++) {
            ASSERT_TRUE(expected->equal_value_at(actual.get(), i, i))
        << "at " << i << ": expected " << expected->toString(i) << ", but got "
        << actual->toString(i);
        }
    }

    void assertEqualVectors(
        const VectorPtr &expected,
        const VectorPtr &actual,
        const SelectivityVector &rowsToCompare) {
        ASSERT_LE(rowsToCompare.end(), actual->size())
      << "Vectors should at least have the required amount of rows that need "
         "to be verified.";
        ASSERT_TRUE(expected->type()->equivalent(*actual->type()))
      << "Expected " << expected->type()->toString() << ", but got "
      << actual->type()->toString();
        rowsToCompare.applyToSelected([&](vector_size_t i) {
            ASSERT_TRUE(expected->equal_value_at(actual.get(), i, i))
        << "at " << i << ": expected " << expected->toString(i) << ", but got "
        << actual->toString(i);
        });
    }

    void assertCopyableVector(const VectorPtr &vector) {
        auto copy =
                BaseVector::create(vector->type(), vector->size(), vector->pool());
        copy->copy(vector.get(), 0, 0, vector->size());
    }
} // namespace kumo::pollux::test
